用脚本语言如何得到在<select>中被选中的选项的value和text

来源:百度知道 编辑:UC知道 时间:2024/07/03 12:42:23

<select id="selectId">
<option value="1">111</option>
<option value="2">222</option>
</select>
<script language=javascript>
sel = document.getElementById("selectId");
val = sel.options[sel.selectedIndex].value
tex = sel.options[sel.selectedIndex].text
</script>
val就是选中项的value
tex就是选中项的text

function tt()
{

xx= document.getElementById("se4").value }
在 select 中加上 onchange=tt() 名字为se4

以下测试过 可以用的
<script language="javascript">
function sel(name)
{
alert(name.options[name.selectedIndex].text);
alert(name.value);
alert(name.options[name.selectedIndex].value);
}
</script>
<select name="sel" onchange="sel(this)">
<option valu